package com.sca;


import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@DubboService
public class DemoDubboServiceImpl implements DemoDubboService {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public String sayHello(String name) {
        logger.info("你好 : {}", name);

        // 2025-02-01 注意 : SCA微服务和Dubbo微服务的链路跟踪是不通的两个域,现在是在Dubbo微服务范围内，这里无论代码方式输出
        // traceId+spanId, 还是日志方式输出 traceId+spanId,  这里都是显示 Dubbo微服务范围的相应信息.
        // 获取当前的 Span
        Span currentSpan = Span.current();
        SpanContext spanContext = currentSpan.getSpanContext();
        logger.info("trace context: {},{}", spanContext.getTraceId(), spanContext.getSpanId());

        return "Hello " + name;
    }
}